package com.intexh.quickandroid.module.chat.ChatManager;

import android.content.Context;
import android.content.SharedPreferences;
import android.content.SharedPreferences.Editor;

import com.hyphenate.EMCallBack;
import com.hyphenate.chat.EMClient;
import com.intexh.quickandroid.module.chat.ChatHelper;
import com.intexh.quickandroid.module.chat.bean.ChatMessage;
import com.intexh.quickandroid.module.chat.bean.ChatSession;
import com.intexh.quickandroid.utils.LogCatUtil;


public enum EasemobManager {
    INSTANCE;
    /**
     * 是否登录
     */
    public boolean isLogin() {
        return EMClient.getInstance().isConnected();
    }
    public static void login(String chat_uid, String chat_password,EMCallBack callBack) {
        //回调是在子线程
        EMClient.getInstance().login(chat_uid, chat_password,callBack);
    }

    public static void logout() {
        SharedPreferences sp = ChatHelper.getInstance().getAppContext().getSharedPreferences("session", Context.MODE_PRIVATE);
        Editor edit = sp.edit();
        edit.putString("chat_password", "empty");
        edit.putString("chat_uid", "empty");
        edit.apply();
        ChatMessage.deleteAll();    //清除聊天记录
        ChatSession.deleteAll();    //清除聊天记录
        EMClient.getInstance().logout(true, new EMCallBack() {

            @Override
            public void onSuccess() {
                // TODO Auto-generated method stub
                LogCatUtil.e("frank", "环信退出登录");

            }

            @Override
            public void onProgress(int progress, String status) {
                // TODO Auto-generated method stub

            }

            @Override
            public void onError(int code, String message) {
                // TODO Auto-generated method stub
                LogCatUtil.e("frank", "环信退出登录失败"+message);

            }
        });
    }

}
